package pack;
import java.util.ArrayList;
import java.util.LinkedList;


public class LinkedListVsArrayListInsert {
	
	public static void main(String[] args) {
		LinkedList<String> linked = new LinkedList<>();
		ArrayList<String> array = new ArrayList<>(10000);
		int count = 1000000;
		int heat = 100000;
		int iter = 0;
		long t = 0;
		int j = 0;
		for (int i = 0; i < heat; i++) {
			linked.add(0,"string");
//			linked.remove(0);
			array.add(0,"string");
//			array.remove(0);
		}
		linked.clear();
		array.clear();
		System.out.println("heated");

		
		while(j < count && iter < 50) {
			t = 0;
			t += System.nanoTime();
			linked.add(0,"string");
			linked.add(0,"string");
			linked.add(0,"string");
			linked.add(0,"string");
			linked.add(0,"string");
			t -= System.nanoTime();
			
			t -= System.nanoTime();
			array.add(0,"string");
			array.add(0,"string");
			array.add(0,"string");
			array.add(0,"string");
			array.add(0,"string");
			t += System.nanoTime();
			j++;
			if(t >= 1000) {
				//System.out.println("time difference: " + t);
				System.out.println("iterations: " + j + " iteration: " + j*5);	
				iter++;
			}
		}
	}
	
}
